package com.zy.demo048084.controller;

import com.zy.demo048084.pojo.po.DepartPo;
import com.zy.demo048084.service.Demo2Service;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/openfeign/depart")
public class OpenFeignController {

    private final Demo2Service demo2Service;

    @PostMapping("/")
    public boolean save(@RequestBody DepartPo po) {
        return demo2Service.save(po);
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return demo2Service.delete(id);
    }

    @PutMapping("/")
    public boolean modify(@RequestBody DepartPo po) {
        return demo2Service.modify(po);
    }

    @GetMapping("/get/{id}")
    public DepartPo getById(@PathVariable Long id) {
        return demo2Service.getById(id);
    }

//    @SentinelResource(fallback = "getAllFallback", fallbackClass = FallbackController.class)
    @GetMapping("/list")
    public List<DepartPo> getAll() throws InterruptedException {
        Thread.sleep(5000);
        List<DepartPo> all = demo2Service.getAll();
        System.out.println(all);
        return all;
    }

    // 方法级降级：sentinel降级方法
//    public List<DepartPo> getAllFallback(Throwable throwable) {
//        System.out.println("sentinel方法降级" + throwable.getMessage());
//        return null;
//    }
}
